package com.jstyle.jclife.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.android.flexbox.FlexboxLayoutManager;
import com.jstyle.jclife.R;
import com.jstyle.jclife.utils.ResolveData;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/6/13.
 */

public class SportDataDayAdapter extends RecyclerViewBaseAdapter<String> {



    String[]datas=new String[]{"0","0","0","00:00","0"};
    public SportDataDayAdapter(List<String> mDatas) {
        super(mDatas);
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        HistoryViewHolder historyViewHolder=(HistoryViewHolder)holder;

        if(position==1){
            historyViewHolder.tvDataHistoryDay.setText(ResolveData.getShowDistance(datas[position]));
            historyViewHolder.tvTitleHistoryDate.setText(ResolveData.getDistanceLabel());
        }else{
            historyViewHolder.tvDataHistoryDay.setText(datas[position]);
            historyViewHolder.tvTitleHistoryDate.setText(mDataList.get(position));
        }

        historyViewHolder.viewHorizontal.setVisibility(position == 4 || position == 2 ? View.INVISIBLE : View.VISIBLE);
        //  viewVertical.setVisibility(position > 2 ? View.INVISIBLE : View.VISIBLE);
        ViewGroup.LayoutParams lp = ((RelativeLayout) (historyViewHolder.tvDataHistoryDay.getParent())).getLayoutParams();
        if (lp instanceof FlexboxLayoutManager.LayoutParams) {
            FlexboxLayoutManager.LayoutParams flexboxLp = (FlexboxLayoutManager.LayoutParams) lp;
            flexboxLp.setFlexBasisPercent(position < 3 ? 0.333f : 0.5f);//写1/3部分机型平分不了
        }


    }
    public class HistoryViewHolder extends BaseViewHolder {
        @BindView(R.id.tv_data_history_day)
        TextView tvDataHistoryDay;
        @BindView(R.id.view_Horizontal)
        View viewHorizontal;
        @BindView(R.id.view_Vertical)
        View viewVertical;
        @BindView(R.id.tv_title_history_date)
        TextView tvTitleHistoryDate;

        public HistoryViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    public void setDatas(String[]datas){
        this.datas= datas;
        notifyDataSetChanged();
    }

    @Override
    protected int getLayoutId(int viewType) {
        return R.layout.item_histroy_data;
    }
    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        return new HistoryViewHolder(LayoutInflater.from(parent.getContext()).inflate(getLayoutId(viewType),parent,false));
    }

}
